#include <REGX52.H>
#include "Matrixkey.h"
#include "Delay.h"
u16 MatrixKey(void)
{
   u8 MKeyNum=0;
        P1=0XFF; 
  	  P1_7=0; 
	    if(P1_3==0){Delay(50);while(P1_3==0)Delay(50);MKeyNum=1;};
          if(P1_2==0){Delay(50);while(P1_2==0)Delay(50);MKeyNum=2;};
          if(P1_1==0){Delay(50);while(P1_1==0)Delay(50);MKeyNum=3;};
          if(P1_0==0){Delay(50);while(P1_0==0)Delay(50);MKeyNum=4;};
	    
	  P1=0XFF; 
	  P1_6=0;
	    if(P1_3==0){Delay(50);while(P1_3==0)Delay(50);MKeyNum=5;};
	    if(P1_2==0){Delay(50);while(P1_2==0)Delay(50);MKeyNum=6;};
	    if(P1_1==0){Delay(50);while(P1_1==0)Delay(50);MKeyNum=7;};
	    if(P1_0==0){Delay(50);while(P1_0==0)Delay(50);MKeyNum=8;};
	 P1=0XFF; 
       P1_5=0;
	    if(P1_3==0){Delay(50);while(P1_3==0) Delay(50);MKeyNum=9;};
          if(P1_2==0){Delay(50);while(P1_2==0)Delay(50);MKeyNum=10;};
          if(P1_1==0){Delay(50);while(P1_1==0)Delay(50);MKeyNum=11;};
          if(P1_0==0){Delay(50);while(P1_0==0)Delay(50);MKeyNum=12;};
	    
	  P1=0XFF;   
	  P1_4=0;  
         if(P1_3==0){Delay(50);while(P1_3==0)Delay(50);MKeyNum=13;};
	   if(P1_2==0){Delay(50);while(P1_2==0)Delay(50);MKeyNum=14;};
	   if(P1_1==0){Delay(50);while(P1_1==0)Delay(50);MKeyNum=15;};
         if(P1_0==0){Delay(50);while(P1_0==0)Delay(50);MKeyNum=16;};

  return MKeyNum;

}
